<?php
/**
 * The template for displaying lists of events
 *
 * Queries to do with events will default to this template if a more appropriate template cannot be found
 *
 ***************** NOTICE: *****************
 *  Do not make changes to this file. Any changes made to this file
 * will be overwritten if the plug-in is updated.
 *
 * To overwrite this template with your own, make a copy of it (with the same name)
 * in your theme directory.
 *
 * WordPress will automatically prioritise the template in your theme directory.
 ***************** NOTICE: *****************
 *
 * @package Event Organiser (plug-in)
 * @since 1.0.0
 */

//Call the template header
get_header(); ?>
<?php 

?>
<!-- This template follows the TwentyEleven theme-->
<div id="content" class="clearfix row-fluid">
	<div id="main" class="span12 clearfix" role="main">
			<span class="span4">
				<div class="12" id="events_archive_sidebar">
					<h1>Archivio</h1>
					<ul id="events_archive_widget">
						<li class="active"><a class="load_all" 
								href="javascript:;">Visualizza tutti</a></li>
					<?php $archives = get_events_archive_array();
						foreach ($archives as $a): ?>
						<li>
							<a class="choose_archive_date" 
								href="javascript:;"><?= ucfirst($a['monthname'])." ".$a['year']?></a>
							<input type="hidden" class="archive_month" value="<?= $a['month'] ?>">
							<input type="hidden" class="archive_year" value="<?= $a['year']?>">
						</li>
					<?php endforeach;?>
					</ul>
				</div>
			</span>
			
			<span class="span7" id="">
			<h1>News & Eventi</h1>  
			<br>
			<span class="span12" id="events_container">
			</span>
			
			</span>
		</div>
		
	</div><!-- #content -->
	
	

<script type="text/javascript">
jQuery(document).ready(function(){
	load_all_events();

	
	jQuery('.choose_archive_date').click(function(){
		$('#events_container').css('opacity',0.2);
		$('#events_archive_sidebar').find('.active').removeClass('active');
		$(this).parents('li').addClass('active');
			var month = jQuery(this).parent().find('.archive_month').val();
			var year = jQuery(this).parent().find('.archive_year').val();
			$.post( "<?=home_url("wp-admin/admin-ajax.php")?>",
					{action: "get_events_list",nonce:"<?=  wp_create_nonce("get_events_list_nonce");?>",
						year: year, month:month},
					function(data){
						$('#events_container').html(data);
						$('#events_container').css('opacity',1);
					},
					'json');
	});


	$('.load_all').click(function(){
			load_all_events();
		});
	
});


function load_all_events(){
	$('#events_container').css('opacity',0.2);
	$('#events_archive_sidebar').find('.active').removeClass('active');
	$('.load_all').parents('li').addClass('active');
	$.post( "<?=home_url("wp-admin/admin-ajax.php")?>",
			{action: "get_events_list",nonce:"<?=  wp_create_nonce("get_events_list_nonce");?>"},
			function(data){
				$('#events_container').html(data);
				$('#events_container').css('opacity',1);
			},
			'json');
}

</script>

<!-- Call template sidebar and footer -->
<?php //get_sidebar(); ?>
<?php get_footer(); ?>
